package com.ruoyi.web.controller.school;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.school.domain.PacAuditRecords;
import com.ruoyi.school.domain.dto.PacAuditApplyDTO;
import com.ruoyi.school.domain.dto.PacAuditRecordsListDTO;
import com.ruoyi.school.domain.vo.PacAuditRecordsVo;
import com.ruoyi.school.service.PacAuditRecordsService;
import com.ruoyi.system.domain.TableData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "审批记录")
@RestController
@RequestMapping("/school/audit")
public class PacAuditRecordsController extends BaseController {
    @Resource
    private PacAuditRecordsService pacAuditRecordsService;

    @ApiOperation("排名前五")
    @GetMapping("/top5")
    public AjaxResult top5() {
        List<PacAuditRecords> top5 = pacAuditRecordsService.getTop5();
        return success(top5);
    }

    @GetMapping("/list")
    public TableDataInfo list(PacAuditRecordsListDTO pacAuditRecordsListDTO) {
        TableData<PacAuditRecordsVo> list = pacAuditRecordsService.getList(pacAuditRecordsListDTO);

        return getDataTable2(list.getData(),list.getTotal());
    }

    @GetMapping("/list/teacher")
    public TableDataInfo listByTeacher(PacAuditRecordsListDTO pacAuditRecordsListDTO) {
        TableData<PacAuditRecordsVo> list = pacAuditRecordsService.getListByTeacher(pacAuditRecordsListDTO);

        return getDataTable2(list.getData(),list.getTotal());
    }


    @GetMapping("/details")
    public AjaxResult details(PacAuditRecords pacAuditRecords) {
        PacAuditRecords details = pacAuditRecordsService.details(pacAuditRecords);
        return success(details);
    }

    @Log(title = "审批记录", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody PacAuditRecords pacAuditRecords) {
        pacAuditRecordsService.audit(pacAuditRecords);
        return success();
    }

    /**
     * 学生发起申请
     *
     * @param pacAuditRecords
     * @return
     */
    @Log(title = "审批记录", businessType = BusinessType.INSERT)
    @PostMapping("/apply")
    public AjaxResult apply(@RequestBody PacAuditApplyDTO pacAuditRecords) {
        pacAuditRecordsService.apply(pacAuditRecords);
        return success();
    }

    /**
     * 入党申请
     */
    @PostMapping("/apply/entry")
    public AjaxResult applyEntry(@RequestBody PacAuditApplyDTO pacAuditRecords) {
        pacAuditRecordsService.applyEntry(pacAuditRecords);
        return success();
    }


    /**
     * 删除审批记录
     *
     * @param pacAuditRecords
     * @return
     */
    @Log(title = "审批记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete")
    public AjaxResult delete(PacAuditRecords pacAuditRecords) {
        pacAuditRecordsService.delete(pacAuditRecords);
        return success();
    }

    /**
     * 导出学生的申请记录
     *
     * @param pacAuditRecords
     * @return
     */
    @Log(title = "审批记录", businessType = BusinessType.EXPORT)
    @PostMapping("/myExport")
    public void myExport(HttpServletResponse response, PacAuditRecords pacAuditRecords) {
        List<PacAuditRecords> list = pacAuditRecordsService.myExport(pacAuditRecords);
        ExcelUtil<PacAuditRecords> util = new ExcelUtil<>(PacAuditRecords.class);
        util.exportExcel(response, list, "参数数据");
    }

    /**
     * 查询某个学生 已通过的审批记录，且只查询 那三种
     */
    @GetMapping("/getPassed")
    public TableDataInfo getPassed(Long stuId) {
        startPage();
        List<PacAuditRecords> list = pacAuditRecordsService.getPassed(stuId);
        return getDataTable(list);
    }

    /**
     * 中队长 获取列表
     * @param pacAuditRecordsListDTO
     * @return
     */
    @GetMapping("/list/captain")
    public TableDataInfo listByCaptain(PacAuditRecordsListDTO pacAuditRecordsListDTO) {
        TableData<PacAuditRecordsVo> list = pacAuditRecordsService.listByCaptain(pacAuditRecordsListDTO);

        return getDataTable2(list.getData(),list.getTotal());
    }
    /**
     * 导出学生的申请记录
     *
     * @param pacAuditRecordsListDTO
     * @return
     */
    @Log(title = "审批记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export1")
    public void export1(HttpServletResponse response, PacAuditRecordsListDTO pacAuditRecordsListDTO) {
        TableData<PacAuditRecordsVo> list = pacAuditRecordsService.getList(pacAuditRecordsListDTO);
        ExcelUtil<PacAuditRecordsVo> util = new ExcelUtil<>(PacAuditRecordsVo.class);
        List<PacAuditRecordsVo> data = list.getData();
        util.exportExcel(response, data, "申请记录");
    }


    /**
     * 导出学生的申请记录
     *
     * @param pacAuditRecordsListDTO
     * @return
     */
    @Log(title = "审批记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export2")
    public void export2(HttpServletResponse response, PacAuditRecordsListDTO pacAuditRecordsListDTO) {
        TableData<PacAuditRecordsVo> list = pacAuditRecordsService.listByCaptain(pacAuditRecordsListDTO);
        ExcelUtil<PacAuditRecordsVo> util = new ExcelUtil<>(PacAuditRecordsVo.class);
        List<PacAuditRecordsVo> data = list.getData();
        util.exportExcel(response, data, "申请记录");
    }

    /**
     * 统计数据
     */
    @GetMapping("/statistics")
    public AjaxResult statistics() {
        return success(pacAuditRecordsService.getStatistics());
    }

}
